<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
	<th:block th:include="include :: header('订单状态权限')" />
	<th:block th:include="include :: ztree-css" />
</head>
<body class="white-bg">
	<div class="wrapper wrapper-content animated fadeInRight ibox-content">
		<form class="form-horizontal m" id="form-dept-edit">
			<input id="deptId" name="deptId" type="hidden" th:value="*{deptId}"/>
			<div class="form-group">
				<label class="col-sm-3 control-label ">部门名称：</label>
				<div class="col-sm-8">
					<input class="form-control" type="text" name="deptName" id="deptName" th:value="*{deptName}" readonly="true"/>
				</div>
			</div>
			<div class="form-group" id="authDataScope">
				<label class="col-sm-3 control-label">订单状态</label>
				<div class="col-sm-8">
					<div id="statusTrees" class="ztree"></div>
				</div>
			</div>
		</form>
	</div>
	<th:block th:include="include :: footer" />
	<th:block th:include="include :: ztree-js" />
	<script type="text/javascript">
	
	    $(function() {
			var url = ctx + "order/orderStatusDeptRelation/list?deptId="+$("#deptId").val();
			var options = {
				id: "statusTrees",
		        url: url,
		        check: { enable: true, nocheckInherit: true, chkboxType: { "Y": "ps", "N": "ps" } },
		        expandLevel: 2,
				onCheck: zTreeOnCheck
		    };
			$.tree.init(options);
	    });

		function zTreeOnCheck(event, treeId, treeNode) {
			let obj = JSON.stringify({
				orderStatus: treeNode.id,
				deptId: $("#deptId").val(),
				userId: 1
			})
			if(treeNode.checked){
				//	选中
				var config = {
					url: 'add',
					type: "POST",
					dataType: "json",
					contentType: 'application/json;charset=UTF-8',
					data: obj,
					beforeSend: function () {
						$.modal.loading("正在处理中，请稍后...");
					},
					success: function(result) {
						if(result.code == 0){
							$.modal.closeLoading();
						}
					}
				};
				$.ajax(config)
			}else{
			//	取消选中
				var config = {
					url: 'del',
					type: "PUT",
					dataType: "json",
					contentType: 'application/json;charset=UTF-8',
					data: obj,
					beforeSend: function () {
						$.modal.loading("正在处理中，请稍后...");
					},
					success: function(result) {
						if(result.code == 0){
							$.modal.closeLoading();
						}
					}
				};
				$.ajax(config)
			}
		};
	</script>
</body>
</html>
